﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Data;

public partial class Employee_DeleteInterview : System.Web.UI.Page
{
    string sqlconn = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        sqlconn = WebConfigurationManager.ConnectionStrings["connection"].ToString();
        if (!IsPostBack)
        {
            getdataInterview();
        }
    }

    private void getdataInterview()
    {
        SqlConnection conn = new SqlConnection(sqlconn);
        SqlDataAdapter sqldata = new SqlDataAdapter("select * from tb_Interview", conn);

        DataTable dt = new DataTable();
        try
        {
            conn.Open();
            sqldata.Fill(dt);
            gvInterview.DataSource = dt;
            gvInterview.DataBind();
          
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert(" + ex.Message + ")</script>");
        }
        finally
        {
            conn.Close();
        }
    }
    protected void gvInterview_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection conn = new SqlConnection(sqlconn);
        int id = Convert.ToInt32(gvInterview.DataKeys[e.RowIndex].Value);

        SqlCommand com = new SqlCommand("delete from tb_Interview where InterviewID = " + id + "", conn);
        try
        {
            conn.Open();
            com.ExecuteNonQuery();
            gvInterview.EditIndex = -1;
            Label1.Text = "Delete Success";
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert(" + ex.Message + ")</script>");
        }
        finally
        {
            conn.Close();
        }
        getdataInterview();
    }



    protected void gvInterview_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvInterview.PageIndex = e.NewPageIndex;
        getdataInterview();
    }
}